var api = {
    initGoods:function(req){
        req['serverName']  = '/wx/goods/detail';
        doRequestwithnoheader(req).then(function(res){
            $('.js-goods-intro-template').append(template('js-goods-intro-template',{data:res.data,apiDomain:getApiDomain()}));
            $('.js-goods-content-template').append(template('js-goods-content-template',{data:res.data,apiDomain:getApiDomain()}));
        });
    },

    /*渲染banner*/
    initBanner:function(req){
        req['serverName']  = '/wx/banner/finds';
        doRequestwithnoheader(req).then(function(res){
            $('.js-banner-template').append(template('js-banner-template',{data:res.data.data,apiDomain:getApiDomain()}));
            /*轮播图*/
            new Swiper('.banner_swiper', {
                autoplay: 5000,
                loop: true,
                pagination: '.banner-pagination'
            });
        });
    }

}

var init = (function(){
    /*加载公共头部*/
    main_api.loadCommonHeader({'title':'商品详情','left':'back','right':''})

    /*加载数据*/
    //获取商品ID
    var goods_id = g_params['goods_id'];
    api.initGoods({goods_id:goods_id});
    api.initBanner({});

    /*立即购买*/
    $('#toBuy').click(function(){
        window.location.href = '/wx/html/order_commit.html?goods_id='+g_params['goods_id'];
    });
})(init)
